import { BaseWindow } from "../../../../component/window/BaseWindow";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { Language } from "../../../../../extend/language/Language";
import { ObjCreate } from "../../common/ObjCreate";
import { LoaderManager } from "../../../../../com/gengine/resource/LoaderManager";
import { OneKeyFriendsHeadCellrenderer } from "./OneKeyFriendsHeadCellrenderer";
import { ImageInfo } from "../../../../../com/gengine/resource/info/ImageInfo";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { EffectManager } from "../../../manager/EffectManager";
import { GuideTipsManager } from "../../../manager/GuideTipsManager";
import { GTileList } from "../../../../../com/mui/controls/GTileList";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { PageSelecter } from "../../common/pageSelect/PageSelecter";
type int = number;
//class OneKeyFriendsWin
    
    export  class OneKeyFriendsWin extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this._allPlayers = [];
            this.setSize(458, 463);
            this.titleHeight = 25;
            this.title = Language.getString(69427);
            return;
        }

        protected /* override */ createChildren(): void
        {
            var loc1=0;
            var loc2=null;
            super.createChildren();
            ObjCreate.createBg(17, 36, 420, 380, this);
            this._headBgArr = [];
            loc1 = 0;
            loc1 = 0;
            while (loc1 < 12) 
            {
                loc2 = new Object /* flash.display.Bitmap */();
                loc2.x = 25 + loc1 % 4 * 100;
                loc2.y = 40 + Math.floor(loc1 / 4) * 118;
                this.addChild(loc2);
                this._headBgArr.push(loc2);
                ++loc1;
            }
            LoaderManager.instance.load("OneKeyFriends_headBg.png", this.onHeadBgLoaded);
            this._playerHeadList = ObjCreate.createTileList(this._headBgArr[0].x, this._headBgArr[0].y, 405, 360, this);
            this._playerHeadList.rowHeight = 118;
            this._playerHeadList.columnWidth = 100;
            this._playerHeadList.selectable = false;
            this._playerHeadList.setStyle("cellRenderer", OneKeyFriendsHeadCellrenderer);
            this._pageSelec = ObjCreate.createPageSelecter(186, 393, this);
            this._pageSelec.addEventListener(flash.events.Event.CHANGE, this.onPageChange);
            this._makeFriendsBtn = ObjCreate.createGButton(Language.getString(69428), 186, 422, 95, 26, this);
            this._makeFriendsBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onMakeFriendsBtnClick);
            return;
        }

        /* internal  */onHeadBgLoaded(arg1: ImageInfo): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=this._headBgArr;
            for(loc1 of loc3) 
            {
                loc1.bitmapData = arg1.bitmapData.clone();
            }
            return;
        }

        public setDataProviderer(arg1: Array<any>): void
        {
            if (arg1) 
            {
                this._allPlayers = arg1;
                this.updatePlayers();
            }
            else 
            {
                this._playerHeadList.dataProvider = new DataProvider([]);
            }
            return;
        }

        /* internal  */onMakeFriendsBtnClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc2=null;
            var loc1=[];
            var loc3=0;
            var loc4=this._allPlayers;
            for(loc2 of loc4) 
            {
                loc1.push(loc2.name);
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.OneKeyFriends_MakeFriend, loc1));
            this.hide();
            return;
        }

        /* internal  */onPageChange(arg1: Object /* flash.events.Event */): void
        {
            this.updatePlayers();
            return;
        }

        /* internal  */updatePlayers(): void
        {
            this._pageSelec.maxPage = Math.ceil(this._allPlayers.length / this._pagesize);
            var loc1=(this._pageSelec.currentPage - 1) * this._pagesize;
            var loc2=this._pageSelec.currentPage * this._pagesize > this._allPlayers.length ? this._allPlayers.length : this._pageSelec.currentPage * this._pagesize;
            var loc3=this._allPlayers.slice(loc1, loc2);
            this._playerHeadList.dataProvider = new DataProvider(loc3);
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            EffectManager.glowFilterReg(this._makeFriendsBtn, [new Object /* flash.filters.GlowFilter */(16776960)]);
            var loc1=GuideTipsManager.getGuideTips2(GuideTipsManager.Dir_BL, Language.getString(69433));
            loc1.x = this._makeFriendsBtn.x + this._makeFriendsBtn.width;
            loc1.y = this._makeFriendsBtn.y;
            this.addChild(loc1);
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            EffectManager.glowFilterUnReg(this._makeFriendsBtn);
            if (GuideTipsManager.guideTips2.parent == this) 
            {
                GuideTipsManager.hideGuideTips2();
            }
            return;
        }

        /* internal */ /* var */_allPlayers: Array<any>;

        /* internal */ /* var */_headBgArr: Array<any>;

        /* internal */ /* var */_playerHeadList: GTileList;

        /* internal */ /* var */_makeFriendsBtn: GButton;

        /* internal */ /* var */_pageSelec: PageSelecter;

        /* internal */ /* var */_pagesize: int=12;
    }
